<%@page language="java" contentType="text/html; charset=utf-8"	pageEncoding="utf-8"%>
<html>
<head>

<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script type="text/javascript">
var listUrl="rest/face/list.do?name=${name}";
 
$(document).ready(function () {

	
	
/* 	
 */
 
	/*  $('#month').combobox('setValue','11');//设置默认值为今年 */

    $("#submit-search").click(function () {
        $('#face-dg').datagrid({ queryParams: form2Json("fms") });   //点击搜索
    });

    $("#face-dg").datagrid({
        loadMsg: '数据加载中....',
        //title: '用户管理',
        //height:document.body.clientHeight-60,
        width: '100%',
        url: listUrl,        
// 		loadFilter : function(result) {
// 				if (result.retCode == '0000') {
// 					return result.data;
// 				} else {
// 					return result.retMsg;
// 				}
// 			},
			nowrap : false,
			striped : true,
			remoteSort : false,
			rownumbers : true,
			pagination : true,
			fitColumns : true,
			pageList : [ 10, 15, 20, 25  ],
			frozenColumns : [ [ {
				field : 'id',
				checkbox : true
			}, {
				title : '编号',
				field : 'id',
				width : 0,
				height :10,
				hidden : 'true'
			} ] ],
			
			columns : [ [
			{
				field : 'name',
				title : '用户名',
				width : 10
			},	
			{
				field : 'photo',
				title : '照片',
				align : 'center',
				width : 30
			},
			{
				field : 'type',
				title : '类型',
				align : 'center',
				width : 30,
				formatter:function(value){
					if(value==1){
						return '正常'
					}else if(value==2){
						return '口罩'
					}else{
						return '墨镜'
					}
				}
			},
			{
				field : ' ',
				title : '缩略图',
				width : 40,
				align : 'center',
				formatter: function(value,row,index){
					var host = location.host;
					//return '<img src="/image/'+row.photo+'" width="45px">';
					//alert(value);
					return '<img src="http://'+host+'/photoLab/'+row.photo+'" width="40px">';
			    }
				
			}
			,	
			{
				field : 'createTime',
				title : '创建时间',
				align : 'center',
				width : 30
			},
			{
				field : 'updateTime',
				title : '更新时间',
				align : 'center',
				width : 30
			}

			] ]
		});// end datagrid
		//设置分页控件
		var p = $('#face-dg').datagrid('getPager');
		$(p).pagination({
			pageSize : 10,//每页显示的记录条数，默认为10
			pageList : [ 10, 15, 20, 25 ],//可以设置每页记录条数的列表
			beforePageText : '第',//页数文本框前显示的汉字
			afterPageText : '页    共 {pages} 页',
			displayMsg : '当前显示 {from} - {to} 条记录   共 {total} 条记录',
			onBeforeRefresh : function() {
				$(this).pagination('loading');
				$(this).pagination('loaded');
			}

		});//end pagination

	})
	//end ready
	
	
	/* function stateChange(id,status){
		$.post("rest/faceUpdate.do",{"id":id,"status":status},function(data){
			if(data.retCode=="0000"){
				$('#face-dg').datagrid("reload");
			}
		});
		
	} */
	
	
	
	function addface() {
		var url = "face/add.do?name=${name}";
		$.post(url, {}, function(data) {
			$("#center").empty();
			$("#center").html(data);
			$.parser.parse($("#center"));
		});
	}
	
	function showCenter(url,t) {
		var t = $(t);
		
	    $.ajax({
		url:url, 
		type:"get",
	    beforeSend:function(XMLHttpRequest) {
	         $("#center").html("<div class='loading'>页面加载中</div>");
	     },
	    success:function(data) {
	        $("#center").empty();
	        $("#center").html(data);
	        $.parser.parse($("#center"));
	        noword();
	    }
	    });
	}
	
	function editface() {
		var rows = $('#face-dg').datagrid('getSelections');
		if (rows.length != 1) {
			$.messager.alert('操作提示', "请先选择一条要编辑的信息！");
			return;
		}
		var row = $('#face-dg').datagrid('getSelected');
		var id = row.id;
		var url = "face/edit.do";
		$.post(url, row, function(data) {
			$("#center").empty();
			$("#center").html(data);
			$.parser.parse($("#center"));
		});
	}

	function removeface() {
		var array = $('#face-dg').datagrid('getSelections');
		var ids = new Array();

		for ( var i = 0; i < array.length; i++) {//组成一个字符串，ID主键之间用逗号隔开
			
			ids[i] = array[i].id;
		}

		ids = ids.join(',');

		if (array != "") {
			$.messager.defaults = {
				ok : "确定",
				cancel : "取消"
			};
			$.messager.confirm('操作提示', '是否要删除该信息？', function(r) {
				if (r) {
					$.post('rest/face/del.do', {
						ids : ids
					}, function(response) {
						if (response.retCode == "0000") {
							$('#face-dg').datagrid('reload');
							$.messager.alert('操作提示', "删除成功", 'info');
							$.post('http://'+host+'/faceApi/delPhoto',{ids:'ids'},function(){ })
						} else {
							$.messager.alert('操作提示', "删除失败", 'error');
						}
					});
				}
			});
		} else {
			$.messager.alert('操作提示', "请先选择要删除的信息！");
		}

	};
	
// 	照片回显
	function image(value,row,index){
		var host = location.host;
		//return '<img src="/image/'+row.photo+'" width="45px">';
		return '<img src="http://'+host+'/faceServer_tomcat/webapps/photoLab/'+row.photo+'" width="45px">';
	}
	
//搜索
	function search(){
	var ids = $("input[id='tid']").val();
	//console.log(ids)
	 $.ajax({
     	 url: "",
     	 type:'post',
    	 data: { 'ids' : ids},
    	 success:function (result){  
     		 alert("result");
     	 }  
     	 });  
}
//上传照片
function addfacephoto(){
	var url = "face/addphoto.do?name=${name}";
	
	$.post(url, {}, function(data) {
		
		$("#center").empty();
		$("#center").html(data);
		$.parser.parse($("#center"));
	});
}
	
function back(url){
	$.get(url, {}, function(data){
		$("#center").empty();
        $("#center").html(data);
        $.parser.parse($("#center"));
    });
}
</script>
</head>
<body>
  <div class="linkbar"><a>人员管理 /</a><a>人脸库管理</a></div>
		<div class="formtoolbar">
			<form id="fms" method="post" novalidate>
			    
				<!-- <i>姓名</i>
				<input id="name" name="name" style="width:100px" />

				<a id="submit-search" class="easyui-linkbutton">搜索</a> -->
			</form>
		</div>
	</div> 
		<div class="clear"></div>
		<div id="face-dg" toolbar="#toolbar" style="height:650px" ></div>

		<div id="toolbar">
			<a href="#"	class="easyui-linkbutton" iconCls="icon-edit" plain="true"	onclick="addface()">拍照录入</a>
			<a href="#"	class="easyui-linkbutton" iconCls="icon-edit" plain="true"	onclick="addfacephoto()">上传照片</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeface()">删除</a> 
 			<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="back('person/index.do')">返回</a>
		</div>
</body>
</html>